#pragma once
#include "windows.h"
#include <iostream>


class CodePerformanceAnalysis
{
public:
	CodePerformanceAnalysis(){
		LARGE_INTEGER litmp;
		QueryPerformanceFrequency(&litmp);
		m_dfFrequence = (double) litmp.QuadPart;
	}
	double m_dfFrequence;

	static CodePerformanceAnalysis& GetInstance(){ return m_instance; }
protected:
	static CodePerformanceAnalysis m_instance;

};

CodePerformanceAnalysis CodePerformanceAnalysis::m_instance;

class PerformanceCounter
{
public:
	PerformanceCounter(const std::string& str){
		m_str = str;
		std::cout<<"Begin "<<m_str.c_str()<< " Analysis :" << std::endl;
		QueryPerformanceCounter(&m_tBegin);		
	}
	~PerformanceCounter(){
		QueryPerformanceCounter(&m_tExit);
		double useTime = (m_tExit.QuadPart - m_tBegin.QuadPart )/CodePerformanceAnalysis::GetInstance().m_dfFrequence;
		std::cout << "End " << m_str.c_str() << " Analysis(" << useTime << " sec)" <<  std::endl;		
	}

	void DoNothing(){ NULL; }

protected:
	LARGE_INTEGER m_tBegin;
	LARGE_INTEGER m_tExit;
	std::string m_str;
};



#define  BEGIN_PERFORMANCE_ANALYSIS(x) do{ PerformanceCounter perfCnt(x);
#define  END_PERFORMANCE_ANALYSIS }while(false);